//
//  PassViewViewController.m
//  坦克大战
//
//  Created by 宗大丞 on 16/5/24.
//  Copyright © 2016年 Zong. All rights reserved.
//

#import "PassViewViewController.h"
#import "Factory.h"
#import "ViewController.h"

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface PassViewViewController ()

@end

@implementation PassViewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
}

- (void)initUI {
    
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    imgView.image = [UIImage imageNamed:@"tank_back"];
    [self.view addSubview:imgView];
    
#if 0
    UILabel *stageLabel = [[UILabel alloc] initWithFrame:CGRectMake(75, 200, WIDTH - 150, 40)];
    stageLabel.textAlignment = NSTextAlignmentCenter;
    stageLabel.text = self.tip;
    stageLabel.textColor = [UIColor redColor];
    stageLabel.font = [UIFont fontWithName:@"Party LET" size:40];
    stageLabel.numberOfLines = 0;
    stageLabel.layer.borderColor = [UIColor redColor].CGColor;
    stageLabel.layer.cornerRadius = 20;
    [self.view addSubview:stageLabel];
#endif
    
    if (![self.tip isEqualToString:@"GAME OVER"]) {
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(WIDTH / 2 - 75, HEIGHT - 100, 150, 50);
        [btn setTitle:@"NEXT" forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor blackColor];
        btn.titleLabel.font = [UIFont fontWithName:@"Party LET" size:40];
        btn.titleLabel.textColor = [UIColor redColor];
        btn.layer.borderColor = [UIColor redColor].CGColor;
        btn.layer.cornerRadius = 20;
        [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];
    }
    else {
        
        imgView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"gameover.jpg" ofType:nil]];
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(WIDTH / 2 - 75, HEIGHT - 100, 150, 40);
        [btn setTitle:@"Restart" forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor orangeColor];
        btn.titleLabel.font = [UIFont fontWithName:@"Party LET" size:40];
        btn.titleLabel.textColor = [UIColor redColor];
        btn.layer.borderColor = [UIColor cyanColor].CGColor;
        btn.tag = 111;
        btn.layer.cornerRadius = 20;
        [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];
    }
}

- (void)click:(UIButton *)button {
    
    CATransition *animation = [CATransition animation]; animation.duration = 1.5;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.type = kCATransitionPush;
    animation.subtype = kCATransitionFromLeft;
    [self.view.window.layer addAnimation:animation forKey:nil];
    
    [self dismissViewControllerAnimated:NO completion:nil];

    //游戏结束,重新开始.
    if (button.tag == 111) {
        
        [self.viewController restart];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
